package cn.twh.wall.exception;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@ControllerAdvice
@Slf4j
public class GlobalErrorHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public JSONObject resolveException(Exception ex) {
        log.error("GlobalException Handler by annotation", ex);
        JSONObject resp = new JSONObject();
        resp.put("code", "9999");
        resp.put("msg", "挡板系统未知异常" + ex.getMessage());
        return resp;
    }
}
